#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000;
int n, m;
int mp[maxn][maxn];


void Floyd(int n){
    int ans_i = -1, ans_value = 1e9;
    int MAX;
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                mp[i][j] = min(mp[i][j] , mp[i][k] + mp[k][j]);
            }

        }
    }

    for(int i = 1; i <= n; i++){
        MAX = -1;
        for(int j = 1; j <= n; j++){
            if(MAX < mp[i][j]){
                MAX = mp[i][j];
            }
        }
        if(MAX < ans_value){
            ans_i = i;
            ans_value = MAX;
        }
    }

    if(ans_i == -1){
        cout << "0" << endl;
    }else{
        cout << ans_i << " " << ans_value << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(i == j) mp[i][j] = 0;
            else mp[i][j] = 1e9;
        }
    }

    while(m--){
        int x,y,z;
        cin >> x >> y >> z;
        mp[x][y] = min(mp[x][y], z);
        mp[y][x] = min(mp[y][x], z);

    }

    Floyd(n);



    return 0;
}
